<template>
  <div>
    <input v-model="companyName" placeholder="输入股权穿透公司名" />
    <button @click="uploadFile">下载 Excel</button>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data(){
    return{
      companyName:''
    }
  },
  methods: {
    async downloadExcel() {
      try {
        const params = {
          companyName:this.companyName
        };
        const response = await axios.get('/api/download',{ params,responseType: "arraybuffer" })
        const fileName =`${this.companyName}.xlsx`
        const url = window.URL.createObjectURL(new Blob([response.data]))
        const link = document.createElement('a');
        link.href = url;
        link.download =fileName ;
        link.click();

      } catch (err) {
        console.error(err)
      }
    },
    async uploadFile() { 
      const data = { name: 1, age: 23 }
      const response = await axios.post('/api/uploadFile', data)
    }
  }
}
</script>
